//
//  DebatebrainstormViewController.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/15.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "DebatebrainstormViewController.h"
#import "DebatebrainstormMyTableViewCell.h"
#import "ParticularsViewController.h"
#import "DebateThestormTabulation.h"//辩论列表

@interface DebatebrainstormViewController ()<UITableViewDataSource,UITableViewDelegate>

{
    //辩论列表
    NSMutableArray * _DebateThestormTabulationArr;
    
    NSMutableArray *_DebateThestormTabulationArrTwo;
}

@property(nonatomic, strong) UITableView * tableView;


@end

@implementation DebatebrainstormViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    
    self.title=@"辩论风暴";
    //导航条内容颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    //系统时间信号颜色
    //self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    //导航条左边按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui1"] style:UIBarButtonItemStyleDone target:self action:@selector(clickLeftBarButton)];
    //导航条右边按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fenlei"] style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;  // 侧滑返回
    [self setTableViewUp];
    
    //数据解析、
    [self setDebateThestormTabulationUp];

}

#pragma park    **获取辩论列表
- (void)setDebateThestormTabulationUp
{
    NSString *userid = [KQUserDefaults readUserDataWithKey:@"userid"];
    
    NSDictionary *dicc = @{@"userid":userid,
                           @"type":@"2",
                           @"page":@"1",
                           @"index":@"3",
                           @"quality":@"0"
                           };
    [KQNetWork postWithURLString:[NSString stringWithFormat:@"%@/api/think/index",MAIN_URL] parameters:dicc success:^(NSDictionary *dic) {
        
        //_debateThestormModel = [[DebateThestormModel alloc] initWithDictionary:dic];
        
        
        _DebateThestormTabulationArr = [NSMutableArray array];
        _DebateThestormTabulationArrTwo = [NSMutableArray array];
        DebateThestormTabulation * model= [[DebateThestormTabulation alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        
        
        
        for (NSDictionary * dicList in model.list)
        {
            DebateThestormTabulation_list * modelList =[[DebateThestormTabulation_list alloc] init];
            
            [modelList setValuesForKeysWithDictionary:dicList];
            
            DebateThestormTabulation_list_comment *modelListComment = [[DebateThestormTabulation_list_comment alloc] init];
            
            [modelListComment setValuesForKeysWithDictionary:modelList.comment];
            
            [_DebateThestormTabulationArr addObject:modelList];
            
            [_DebateThestormTabulationArrTwo addObject:modelListComment];
            
            [self.tableView reloadData];
            
        }
        
        
        //[self.tableView.mj_header endRefreshing];
        
        
    }
                         failure:^(NSError *error)
     {
         NSLog(@"请求错误");
     }];
}
//导航条返回按钮响应
- (void)clickLeftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}
//导航条右边按钮响应
- (void)clickRightButton
{
    
}
- (void)setTableViewUp{
    
    _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(66), UIScreenWidth, UIScreenHeight-46) style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
    [self.view addSubview:_tableView];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _DebateThestormTabulationArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat ffloat;
    
        DebateThestormTabulation_list_comment * _model_list_comment = _DebateThestormTabulationArrTwo[indexPath.row];
        
        if (![_model_list_comment.head_img isEqualToString:@""]) {
            ffloat = kHeightScale(205);
        }else
        {
            ffloat = kHeightScale(178);
        }
        return ffloat;
    
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * str = @"biao";
    DebatebrainstormMyTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell=[[DebatebrainstormMyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.model=_DebateThestormTabulationArr[indexPath.row];
    cell.list_comment=_DebateThestormTabulationArrTwo[indexPath.row];
    if (indexPath.row == _DebateThestormTabulationArr.count-1) {
        cell.lineBack.hidden = YES;
    } else {
        cell.lineBack.hidden = NO;
    }

    return cell;
    
}
//点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[ParticularsViewController new] animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
